import 'package:flutter/material.dart';
import 'package:qunaimedical/im/common_widgets.dart';
import 'package:qunaimedical/im/wx_expression.dart';

class ItemConversationProps {
  String name;
  String lastMsg;
  String time;
  int unreadCount;
  String? avatar;

  ItemConversationProps({
    required this.name,
    required this.lastMsg,
    required this.time,
    required this.unreadCount,
    this.avatar,
  });
}

class ItemConversation extends StatelessWidget {
  final VoidCallback? onTap;
  final ItemConversationProps props;

  const ItemConversation({
    Key? key,
    required this.props,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      highlightColor: Colors.grey[300],
      onTap: onTap,
      child: Container(
        height: 74,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Stack(
              children: [
                // 头像
                Positioned(
                  child: Container(
                    margin: EdgeInsets.only(
                      left: 16,
                      top: 14,
                      bottom: 14,
                      right: 11,
                    ),
                    child: // 头像，可以替换为用户相关的头像url
                        Image.asset(
                      'images/contact_default_avatar.png',
                      fit: BoxFit.fill,
                    ),
                  ),
                ),
                // 未读数
                Positioned(
                  top: 10,
                  right: 5,
                  child: unreadCoundWidget(props.unreadCount),
                ),
              ],
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        // 姓名
                        Expanded(
                          child: Container(
                            padding: EdgeInsets.only(top: 10),
                            child: Text(
                              props.name,
                              maxLines: 1,
                              textAlign: TextAlign.left,
                              style: TextStyle(
                                color: Colors.black,
                              ),
                            ),
                          ),
                        ),
                        // 时间
                        Container(
                          margin: EdgeInsets.only(left: (5), right: (12)),
                          child: Text(
                            props.time,
                            maxLines: 1,
                            style: Theme.of(context).textTheme.caption,
                          ),
                        ),
                      ],
                    ),
                  ),
                  // 详情
                  Expanded(
                    flex: 1,
                    child: Container(
                      padding: EdgeInsets.only(right: (10)),
                      child: ExpressionText(
                        props.lastMsg,
                        TextStyle(
                          color: Color.fromRGBO(153, 153, 153, 1),
                          fontSize: (14),
                        ),
                        maxLine: 1,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
